package com.yhg.Test;

import com.yhg.dao.UserDao;
import com.yhg.service.UserService;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
//BeanFactory快速入门
//而函数 单例模式
public class BeanFactoryTest {

    public static void main(String[] args) {
        //创建工厂对象
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        //创建一个读取器（xml）
        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
        //读取器绑定工厂
        reader.loadBeanDefinitions("beans.xml");
        //根据ID获取Bean实例对象
        UserService userService = (UserService) factory.getBean("userService");
//        System.out.println(userService);

        UserDao userDao = (UserDao) factory.getBean("userDao");
        System.out.println(userDao);

    }
}
